#!user/bin/env python3
# -- coding: utf-8 --
import os

from lxml import etree
import requests

url = 'https://so.gushiwen.cn/user/login.aspx?from=http://so.gushiwen.cn/user/collect.aspx'
user_agent = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36'}
r = requests.get(url=url, headers=user_agent).text
anlytical_data = etree.HTML(r)
img_src = 'https://so.gushiwen.cn' + anlytical_data.xpath('//*[@id="imgCode"]/@src')[0]
r = requests.get(url=img_src, headers=user_agent).content
# if not os.path.exists('./textdata'):
#     os.mkdir('./textdata')
with open('./testdata.png', 'wb') as file:
    file.write(r)
